using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace PKGames.AssetBundleSystem
{
	public class SceneLoadRequest : IEnumerator
	{
		private string _sceneName = string.Empty;

		private bool _isAdditive;

		private AsyncOperation _asyncOperation;

		private bool _isDone;

		public object Current => null;

		public SceneLoadRequest(string sceneName, bool isAdditive)
		{
			_sceneName = sceneName;
			_isAdditive = isAdditive;
			_asyncOperation = SceneManager.LoadSceneAsync(_sceneName, _isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);
		}

		public bool MoveNext()
		{
			return Update();
		}

		public void Reset()
		{
		}

		private bool Update()
		{
			if (IsLoadSceneAsyncFinished())
			{
				_isDone = true;
			}
			return !_isDone;
		}

		private bool IsLoadSceneAsyncFinished()
		{
			return _asyncOperation != null && _asyncOperation.isDone;
		}
	}
}
